package com.manage.modules.controller;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.manage.common.annotation.Log;
import com.manage.common.core.controller.BaseController;
import com.manage.common.core.domain.AjaxResult;
import com.manage.common.enums.BusinessType;
import com.manage.modules.vo.TBaseDataRecordVo;
import com.manage.modules.bo.TBaseDataRecordQueryBo;
import com.manage.modules.bo.TBaseDataRecordAddBo;
import com.manage.modules.bo.TBaseDataRecordEditBo;
import com.manage.modules.service.ITBaseDataRecordService;
import com.manage.common.utils.poi.ExcelUtil;
import com.manage.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 数据记录Controller
 *
 * @author wx
 * @date 2021-09-14
 */
@Api(value = "数据记录控制器", tags = {"数据记录管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/modules/dataRecord")
public class TBaseDataRecordController extends BaseController {

    private final ITBaseDataRecordService iTBaseDataRecordService;

    /**
     * 查询数据记录列表
     */
    @ApiOperation("查询数据记录列表")
    @PreAuthorize("@ss.hasPermi('modules:dataRecord:list')")
    @GetMapping("/list")
    public TableDataInfo<TBaseDataRecordVo> list(TBaseDataRecordQueryBo bo) {
        startPage();
        List<TBaseDataRecordVo> list = iTBaseDataRecordService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出数据记录列表
     */
    @ApiOperation("导出数据记录列表")
    @PreAuthorize("@ss.hasPermi('modules:dataRecord:export')")
    @Log(title = "数据记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<TBaseDataRecordVo> export(TBaseDataRecordQueryBo bo) {
        List<TBaseDataRecordVo> list = iTBaseDataRecordService.queryList(bo);
        ExcelUtil<TBaseDataRecordVo> util = new ExcelUtil<TBaseDataRecordVo>(TBaseDataRecordVo.class);
        return util.exportExcel(list, "数据记录");
    }

    /**
     * 获取数据记录详细信息
     */
    @ApiOperation("获取数据记录详细信息")
    @PreAuthorize("@ss.hasPermi('modules:dataRecord:query')")
    @GetMapping("/{dataId}")
    public AjaxResult<TBaseDataRecordVo> getInfo(@PathVariable("dataId") Long dataId) {
        return AjaxResult.success(iTBaseDataRecordService.queryById(dataId));
    }

    /**
     * 新增数据记录
     */
    @ApiOperation("新增数据记录")
    @PreAuthorize("@ss.hasPermi('modules:dataRecord:add')")
    @Log(title = "数据记录", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody TBaseDataRecordAddBo bo) {
        return toAjax(iTBaseDataRecordService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改数据记录
     */
    @ApiOperation("修改数据记录")
    @PreAuthorize("@ss.hasPermi('modules:dataRecord:edit')")
    @Log(title = "数据记录", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@RequestBody TBaseDataRecordEditBo bo) {
        return toAjax(iTBaseDataRecordService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除数据记录
     */
    @ApiOperation("删除数据记录")
    @PreAuthorize("@ss.hasPermi('modules:dataRecord:remove')")
    @Log(title = "数据记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{dataIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] dataIds) {
        return toAjax(iTBaseDataRecordService.deleteWithValidByIds(Arrays.asList(dataIds), true) ? 1 : 0);
    }
}
